﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.ValentineUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import flash.text.*;
    import org.aswing.event.*;
    import Classes.orders.Valentines2011.*;
    import Display.aswingui.*;

    public class ValentineCardViewDialogView extends GenericDialogView {

        protected var m_cardData:Array;
        protected var m_admirer:Admirer;
        protected var m_loader:Loader;
        private var m_picPane:AssetPane;
        protected var m_currentCard:int = 0;
        protected var m_cardHolder:JPanel;
        protected var m_activeCard:PicturePane;
        protected var m_cardMessage:AssetPane;
        protected var m_leftButton:JButton;
        protected var m_rightButton:JButton;
        protected var m_tform:TextFormat;
        protected var m_textHolder:JPanel;

        public function ValentineCardViewDialogView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:int=0, _arg5:Function=null, _arg6:String="", _arg7:int=0, _arg8:String="", _arg9:Function=null, _arg10:String=""){
            this.m_cardData = _arg1["cardData"];
            this.m_admirer = _arg1["admirer"];
            super(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10);
        }
        override protected function makeBackground():void{
            if (m_bgAsset){
                ASwingHelper.setSizedBackground(this, m_bgAsset, new Insets(0, 0, 10));
            };
        }
        override protected function createButtonPanel():JPanel{
            var _local1:JPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
            m_acceptTextName.toUpperCase();
            var _local2:CustomButton = new CustomButton(m_acceptTextName, null, "GreenButtonUI");
            if (this.m_admirer.uid == "-1"){
                _local2.setEnabled(false);
            };
            _local2.addActionListener(onAccept, 0, true);
            _local1.append(_local2);
            return (_local1);
        }
        override protected function createInteriorHolder():JPanel{
            var _local1:JPanel;
            var _local2:JPanel;
            _local1 = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, -10, SoftBoxLayout.TOP));
            _local2 = createHeaderPanel();
            ASwingHelper.prepare(_local2);
            textArea = this.createTextArea();
            ASwingHelper.prepare(textArea);
            _local1.append(_local2);
            _local1.append(ASwingHelper.verticalStrut(30));
            _local1.append(textArea);
            _local1.append(ASwingHelper.verticalStrut(BUTTON_MARGIN));
            var _local3:JPanel = this.createButtonPanel();
            _local1.append(_local3);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function createTextArea():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER, 6);
            var _local2:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER, 13);
            ASwingHelper.setEasyBorder(_local2, 0, 3);
            var _local3:JPanel = this.createSenderHolder();
            this.m_leftButton = new JButton();
            this.m_rightButton = new JButton();
            this.m_currentCard = (this.m_cardData["length"] - 1);
            this.m_cardHolder = this.createCardWithTitle(this.m_currentCard);
            this.m_leftButton.wrapSimpleButton(new SimpleButton(m_assetDict["market_prev_up"], m_assetDict["market_prev_over"], m_assetDict["market_prev_down"], m_assetDict["market_prev_up"]));
            this.m_rightButton.wrapSimpleButton(new SimpleButton(m_assetDict["market_next_up"], m_assetDict["market_next_over"], m_assetDict["market_next_down"], m_assetDict["market_next_up"]));
            this.m_leftButton.addActionListener(this.movePrev, 0, true);
            this.m_rightButton.addActionListener(this.moveNext, 0, true);
            this.m_leftButton.setEnabled(false);
            if (this.m_cardData["length"] <= 1){
                this.m_rightButton.setEnabled(false);
            };
            ASwingHelper.setEasyBorder(this.m_leftButton, 2);
            ASwingHelper.setEasyBorder(this.m_rightButton, 2);
            _local2.appendAll(this.m_leftButton, this.m_cardHolder, this.m_rightButton);
            _local1.appendAll(_local3, _local2);
            return (_local1);
        }
        override protected function createCloseButtonPanel():JPanel{
            var _local1:JPanel = new JPanel(ASwingHelper.softBoxLayoutVertical);
            var _local2:JButton = ASwingHelper.makeMarketCloseButton();
            _local2.addEventListener(MouseEvent.CLICK, onCancel, false, 0, true);
            _local1.append(_local2);
            ASwingHelper.setEasyBorder(_local2, 3, 0, 0, 10);
            return (_local1);
        }
        protected function movePrev(_arg1:AWEvent):void{
            this.m_currentCard++;
            var _local2:ValentineCard = this.m_cardData[this.m_currentCard];
            var _local3:String = _local2.message;
            this.m_activeCard.changeCard(_local2);
            var _local4:TextField = (this.m_cardMessage.getAsset() as TextField);
            _local4.text = _local3.toUpperCase();
            _local4.setTextFormat(this.m_tform);
            this.m_cardMessage.setAsset(_local4);
            if (this.m_currentCard > 0){
                this.m_rightButton.setEnabled(true);
            };
            if (this.m_currentCard == (this.m_cardData["length"] - 1)){
                this.m_leftButton.setEnabled(false);
            };
            var _local5:Object = new Object();
            _local5.index = this.m_currentCard;
            dispatchEvent(new GenericObjectEvent(GenericObjectEvent.REFRESH_ACHIEVEMENT, _local5, true));
            ASwingHelper.prepare(this.parent);
        }
        protected function moveNext(_arg1:AWEvent):void{
            this.m_currentCard--;
            var _local2:ValentineCard = this.m_cardData[this.m_currentCard];
            var _local3:String = _local2.message;
            this.m_activeCard.changeCard(_local2);
            var _local4:TextField = (this.m_cardMessage.getAsset() as TextField);
            _local4.text = _local3.toUpperCase();
            _local4.setTextFormat(this.m_tform);
            this.m_cardMessage.setAsset(_local4);
            if (this.m_leftButton.isEnabled() == false){
                this.m_leftButton.setEnabled(true);
            };
            if (this.m_currentCard == 0){
                this.m_rightButton.setEnabled(false);
            };
            var _local5:Object = new Object();
            _local5.index = this.m_currentCard;
            dispatchEvent(new GenericObjectEvent(GenericObjectEvent.REFRESH_ACHIEVEMENT, _local5, true));
            ASwingHelper.prepare(this.parent);
        }
        protected function createSenderHolder():JPanel{
            var _local2:DisplayObject;
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            this.m_picPane = new AssetPane();
            this.m_picPane.setPreferredSize(new IntDimension(50, 50));
            if (this.m_admirer.portrait != null){
                this.m_loader = LoadingManager.load(this.m_admirer.portrait, this.onPortraitLoad, LoadingManager.PRIORITY_HIGH);
            } else {
                _local2 = (new EmbeddedArt.hud_no_profile_pic() as DisplayObject);
                this.m_picPane.setAsset(_local2);
            };
            var _local3:String = this.m_admirer.name;
            var _local4:AssetPane = ASwingHelper.makeMultilineText(ZLoc.t("Dialogs", "ValUIView_message", {friendName:_local3}), 360, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 14, EmbeddedArt.darkBrownTextColor);
            this.m_tform = new TextFormat(EmbeddedArt.TITLE_FONT, 14, EmbeddedArt.whiteTextColor, null, null, null, null, null, TextFormatAlign.CENTER);
            _local1.appendAll(this.m_picPane, _local4);
            var _local5:JPanel = ASwingHelper.centerElement(_local1);
            return (_local5);
        }
        protected function onPortraitLoad(_arg1:Event):void{
            this.m_picPane.setAsset(_arg1.target.content);
        }
        protected function createCardWithTitle(_arg1:int):JPanel{
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local3:Dictionary = Global.gameSettings.getValentinesAssets();
            var _local4:ValentineCard = this.m_cardData[_arg1];
            var _local5:String = _local4.message;
            this.m_textHolder = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER);
            this.m_textHolder.setPreferredHeight(35);
            this.m_textHolder.setMinimumHeight(35);
            this.m_textHolder.setMaximumHeight(35);
            this.m_cardMessage = ASwingHelper.makeMultilineCapsText(_local5, 342, EmbeddedArt.TITLE_FONT, TextFormatAlign.CENTER, 14, EmbeddedArt.whiteTextColor);
            this.m_textHolder.append(this.m_cardMessage);
            this.m_activeCard = new PicturePane(_local3, _local4);
            ASwingHelper.setSizedBackground(_local2, this.m_activeCard);
            _local2.appendAll(ASwingHelper.verticalStrut(10), this.m_textHolder);
            return (_local2);
        }

    }
}//package Display.ValentineUI 
